package com.zhang.family_doctor.controller;

import com.zhang.family_doctor.dto.ResidentDto;
import com.zhang.family_doctor.dto.ResidentFilesDto;
import com.zhang.family_doctor.entity.MemberFamily;
import com.zhang.family_doctor.entity.R;
import com.zhang.family_doctor.entity.Resident;
import com.zhang.family_doctor.entity.ResidentHealth;
import com.zhang.family_doctor.service.ResidentService;
import com.zhang.family_doctor.vo.ResidentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 居民模块
 */
@Api(tags = "居民模块相关接口")
@RestController
@RequestMapping("/resident")
@Slf4j
public class ResidentController {

    @Autowired
    private ResidentService residentService;

    @ApiOperation("发送验证码接口")
    @PostMapping("/sendMsg")
    public R<String> sendMsg(String phone){
        log.info("发送验证码接口:{}",phone);
        return residentService.sendMsg(phone);
    }

    @ApiOperation("注册居民")
    @PostMapping("/register")
    public R<Map<String, Object>> register(@RequestBody Resident resident){
        log.info("注册居民：{}",resident);
        return residentService.register(resident);
    }

    @ApiOperation("新建档案")
    @PostMapping("/newFile")
    public R<String> newFile(@RequestBody Resident resident , HttpServletRequest request){
        log.info("新建档案：{}",resident);
        return residentService.newFile(resident,request);
    }

    @ApiOperation("后台新建居民档案基本信息")
    @PostMapping("/backgroundNewResidentFiles")
    public R<String> backgroundNewResidentFiles(@RequestBody ResidentFilesDto residentFilesDto){
        log.info("后台新建居民档案基本信息：{}",residentFilesDto);
        return residentService.backgroundNewResidentFiles(residentFilesDto);
    }

    @ApiOperation("后台新建完善的居民档案")
    @PostMapping("/improveResidentArchives")
    public R<String> improveResidentArchives(@RequestBody ResidentFilesDto residentFilesDto){
        log.info("后台新建完善的居民档案：{}",residentFilesDto);
        return residentService.improveResidentArchives(residentFilesDto);
    }

    @ApiOperation("居民登录")
    @GetMapping("/login")
    public R login(String phone , String password){
        log.info("居民登录：{}",phone,password);
        return residentService.login(phone,password);
    }

    @ApiOperation("免登录")
    @GetMapping("/noLogin")
    public R noLogin(String phone,String code){
        log.info("免登录：{}",phone,code);
        return residentService.noLogin(phone,code);
    }

    @ApiOperation("忘记密码")
    @PostMapping("/forgotPassword")
    public R forgotPassword(@RequestBody ResidentVO residentVO){
        log.info("忘记密码：{}",residentVO);
        return residentService.forgotPassword(residentVO);
    }

    @ApiOperation("补全或更新居民信息")
    @PostMapping("/completionOrUpdate")
    public R<String> completionOrUpdate(@RequestBody ResidentDto residentDto,HttpServletRequest request){
        log.info("补全或更新居民信息：{}",residentDto);
        return residentService.completionOrUpdate(residentDto,request);
    }

    @ApiOperation("根据token中的居民id查询居民基础信息")
    @GetMapping("/getResidentById")
    public R<Resident> getResidentById(HttpServletRequest request){
        log.info("根据token中的居民id查询居民基础信息");
        return residentService.getResidentById(request);
    }

    @ApiOperation("根据token中的居民id查询居民健康信息")
    @GetMapping("/getResidentHealthByResidentId")
    public R<ResidentHealth> getResidentHealthByResidentId(HttpServletRequest request){
        log.info("根据token中的居民id查询居民健康信息");
        return residentService.getResidentHealthByResidentId(request);
    }

    @ApiOperation("居民新增家庭成员")
    @PostMapping("/addMemberFamily")
    public R<String> addMemberFamily(@RequestBody MemberFamily memberFamily,HttpServletRequest request){
        log.info("居民新增家庭成员：{}",memberFamily);
        return residentService.addMemberFamily(memberFamily,request);
    }

    @ApiOperation("后台修改居民信息")
    @PostMapping("/updateResident")
    public R<String> updateResident(@RequestBody ResidentFilesDto residentFilesDto){
        log.info("后台修改居民信息：{}",residentFilesDto);
        return residentService.updateResident(residentFilesDto);
    }

    @ApiOperation("修改默认")
    @PostMapping("/setDefault")
    public R<String> setDefault(Integer id ,Integer setDefault,HttpServletRequest request){
        log.info("修改默认：{}",id,setDefault);
        return residentService.setDefault(id,setDefault,request);
    }

}
